// Wire Slave Sender
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

// This example code is in the public domain.

#define CHANNELS 6
#include <Wire.h>

uint16_t data[] = {1000,1100,1200,1300,1400,1500};

#define PPM_MAX 2000
#define PPM_MIN 1000

void setup()
{
  
  //Init as I2C Slave
  Wire.begin(2);
  Wire.onRequest(requestEvent);
}

void loop()
{
  for(int i = 0; i < 6; i++){
     if(data[i]>= PPM_MAX){
       data[i] = PPM_MIN;
     }else{
       data[i]++; 
     }
     
     //if(i!=3){
       //data[i] = 1000; 
    // }
     //data[i] = 2000;
  }
  delay(5);
}

//I2C Request Handler
void requestEvent()
{  
  //digitalWrite(13, !digitalRead(13));
  byte bdata[12];
  for(int i = 0; i < CHANNELS; i++){
    bdata[i*2] = data[i];
    bdata[i*2+1] = data[i]>>8;
  }
  Wire.send(bdata, 12);
  Serial.println("request answerd");
}
